package com.ruoyi.sensitive;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import toolgood.words.IllegalWordsSearch;

import java.util.ArrayList;
import java.util.List;

@Service("sensitiveService")
@Slf4j
public class SensitiveServiceImplV1 implements SensitiveServiceV1{
    @Override
    public SensitiveDTO analysisText(String text) {
        SensitiveDTO sensitiveDTO = new SensitiveDTO();
        List<String> sensitiveTypeList = new ArrayList<>();
        String handleText = text;
        SensitiveWordsUtilV1 sensitiveWordsUtil = SensitiveWordsUtilV1.getInstance();
        IllegalWordsSearch allWords = sensitiveWordsUtil.getAdWords();
        boolean ad = allWords.ContainsAny(text);
        if(ad){
            sensitiveDTO.setIll(true);
            sensitiveTypeList.add("all");
            handleText = allWords.Replace(handleText);
        }
        sensitiveDTO.setType(sensitiveTypeList);
        sensitiveDTO.setHandleContent(handleText);
        sensitiveDTO.setOriginalContent(text);
        return sensitiveDTO;
    }
}
